﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using 温湿度和颗粒度监控测试.ViewModel;
using 温湿度和颗粒度监控测试.Common;

namespace 温湿度和颗粒度监控测试.View
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            DataContext = new MainWindowViewModel();
        }

        private void btn温湿度_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                温湿度.温湿度测试Window win = new 温湿度.温湿度测试Window();
                win.ShowDialog();
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                MessageBoxHelper.Error(ex.Message);
            }
        }

        private void btn颗粒度_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                颗粒度.颗粒度测试Window win = new 颗粒度.颗粒度测试Window();
                win.ShowDialog();
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                MessageBoxHelper.Error(ex.Message);
            }
        }
        综合显示Window 综合显示Win;

        private void btn打开综合显示窗口_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                综合显示Win = new 综合显示Window()
                {
                    Top = Top,
                    Left = Left + Width,
                    窗口关闭Event = () =>
                    {
                        (DataContext as MainWindowViewModel).综合显示Window是否显示 = false;
                    },
                    停止监控Event = () =>
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            (DataContext as MainWindowViewModel).综合显示Window是否监控 = false;
                        });
                    }
                };
                综合显示Win.Show();
                (DataContext as MainWindowViewModel).综合显示Window是否显示 = true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                MessageBoxHelper.Error(ex.Message);
            }
        }

        private void btn开始监控_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                MainWindowViewModel vm = DataContext as MainWindowViewModel;
                if (vm.综合显示Window是否监控)
                {
                    综合显示Win?.停止监控();
                    vm.综合显示Window是否监控 = false;
                }
                else
                {
                    综合显示Win?.开始监控();
                    vm.综合显示Window是否监控 = true;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                MessageBoxHelper.Error(ex.Message);
            }
        }
    }
}
